package com.sky.controller.admin;

import com.sky.CategoryService;
import com.sky.constant.StatusConstant;
import com.sky.dto.AddCategoryDTO;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.vo.CategoryQueryVO;
import com.sky.vo.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.sky.result.Result.success;

/**
 * 菜品管理
 * */
@RestController
@Api(tags = "菜品管理")

@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    /**
     * 新增菜品分类
     * */
    @PostMapping
    @ApiOperation("新增菜品分类")
    public Result<Void> addCategory(@Validated @RequestBody AddCategoryDTO addCategoryDTO){
        categoryService.addCategory(addCategoryDTO);
        return success();
    }
    /**
     * 分页查询
     * */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult<CategoryVO>> page(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult<CategoryVO> pageQuery=categoryService.page1(categoryPageQueryDTO);

        return Result.success(pageQuery);
    }
     @DeleteMapping
     @ApiOperation("删除菜品")
    public Result delete(String id){
        categoryService.deleteById(id);
        return Result.success();
     }
     @ApiOperation("修改菜品")
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return  Result.success();
     }
     @ApiOperation("禁用")
    @PostMapping("/status/{status}")
    public Result qin(@PathVariable Integer status,Long id){
        categoryService.jin(status,id);
        return Result.success();
     }

     @GetMapping("/list")
    public Result list(Integer type){
       List<Category> list= categoryService.list(StatusConstant.ENABLE,type);
       return Result.success(list);
     }


}
